Skip to main content

Nodes String Compiler

The BotX platform includes a powerful String Compiler that allows users to compile string templates with embedded variables, making it easier to create dynamic text content. This tool is akin to templating engines like Mustache, providing flexibility in generating personalized and context-sensitive strings.

Customizable Input Templates

Basic Usage

The String Compiler can process string templates containing variable placeholders. Variables are enclosed in double curly braces ({{ }}) and can access values from a provided data object.

Example

Suppose you have a string template:

"Hello {{object.key1.key2}}, or World!"

To compile this template, you use the data object that contains the necessary data. For instance, if your data object has a nested structure:

Data Object:
{
"object": {
"key1": {
"key2": "value"
}
}
}

When the template is compiled, the output will be:

"Hello value, or World!"

Advanced Usage

The String Compiler supports more complex templates, including nested objects and lists. For example:

"Hello {{object.key1.key2[0]}}, or World! and also {{object.key1.key2[1].a}}"

With the following data object:

Data Object:
{
"object": {
"key1": {
"key2": [314, {"a": "test"}]
}
}
}

The compiled string will be:

"Hello 314, or World! and also test"

System-Level Variables

In addition to user-defined variables, the String Compiler provides access to a set of system-level variables through the __botx__ object. These variables can be useful for including dynamic information like the current date and time.

Example

To include today's date in a string template:

"Today's day is {{__botx__.datetime.utcnow_formatted}}"

The system will automatically provide the current date in a readable format. For example, the output could be:

"Today's day is Monday, 10 June 2024 14:23:05"

__botx__ Variables

The current list of __botx__ variables includes date and time information. Here is a breakdown of the available variables:

  • {{__botx__.datetime.day_name}}: The name of the current day (e.g., "Monday").
  • {{__botx__.datetime.utcnow}}: The current date and time in UTC (e.g., "2024-06-10 14:23:05").
  • {{__botx__.datetime.utcnow_formatted}}: The current date and time in a readable format (e.g., "Monday, 10 June 2024 14:23:05").
  • {{__botx__.datetime.utcnow_time}}: The current time in UTC (e.g., "14:23:05").

Example

To dynamically include the current day and time in a message, you might use:

"Good morning! Today is {{__botx__.datetime.day_name}} and the current time is {{__botx__.datetime.utcnow_time}}."

With this template, assuming today is Monday and the current time is 14:23:05 UTC, the output will be:

"Good morning! Today is Monday and the current time is 14:23:05."

This can be very useful for LLM prompts that require awareness about current time.

Conclusion

The String Compiler in BotX provides a robust and flexible way to generate dynamic content by compiling string templates with embedded variables. By leveraging both user-defined and system-level variables, you can easily create personalized and context-aware text outputs.

For further details or advanced usage scenarios, refer to the additional documentation sections or contact support.